m.controller("settleAccount",function($rootScope,$scope,$location) {

	
	
	$scope.init = function(){
		$scope.add_commodityList=null;
		$scope.commodityList = $rootScope.getCookie("commodity");
		
		
	}
	
	$scope.addSelled = function(){

		if($scope.commodityList != null && $scope.commodityList!=""){
			$scope.add_commodityList = new Array();
            var obj = {};
            for(var temp in $scope.commodityList){
           	 
           	 	obj['userId'] =  $rootScope.userOfLoger.id;
           	 
                obj['commodity'] = {"id":$scope.commodityList[temp].commodity_id};
                obj['number'] = $scope.commodityList[temp].number;
                obj['price'] = $scope.commodityList[temp].price;
                $scope.add_commodityList.push(obj);obj = {};
		}
           
            $.ajax({
    	        type:"POST",
    	        url:"/selled/addSelledListByName",
    	        data:JSON.stringify($scope.add_commodityList),
    	        contentType:"application/json;charset=utf-8",
    	        dataType:"json",
    	        success:function(data){
    	        	
    	        	if(data.success){
    	        		alert("购买成功");
    	        		$scope.$apply(function(){
    	        			$rootScope.deleteCookie("commodity");
        	            	$scope.init();
        	            });
    	        	}else{
    	        		alert("错误");
    	        	}
    	            
    	        }
    		});
	}}
	$scope.addSelledModal = function(){
		if($scope.commodityList == null || $scope.commodityList == ''){
			alert("购物车是空的")
		}else{

			$("#modalid-add-account").modal("toggle");
		}
	}
	
	$scope.backward = function(){
		window.history.back();
	}
  $scope.init();
      

});